package executors.completable.future;

import java.util.concurrent.*;

public class ThenApplyAsyncTest001 {
  public static void main(String[] args) throws ExecutionException, InterruptedException {
    ExecutorService executorService = Executors.newFixedThreadPool(5);
    
    CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(() -> {
      System.out.println("1. " + Thread.currentThread().getName());
      try {
        TimeUnit.SECONDS.sleep(1);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
      return 10;
    }, executorService);
    
    CompletableFuture<Integer> a = completableFuture.thenApplyAsync(count -> {
      System.out.println("2. " + Thread.currentThread().getName());
      return count * 10;
    }, executorService);
    
    CompletableFuture<Integer> integerCompletableFuture = completableFuture.thenApplyAsync(count -> {
      System.out.println("3. " + Thread.currentThread().getName());
      return count + 20;
    }, executorService);
    
    System.out.println(completableFuture.get());
    System.out.println(integerCompletableFuture.get());
  }
}
